<?php
/**
 * @author Garry
 *
 * This wrapper adds an edit and view link
 */
class EditableImageWrapper extends HtmlDisplay  {
	//TODO - Insert your code here
	protected $imgdat;

	public function __construct( $id,$class='') {

		//TODO - Insert your code here
		$this->dat = $this->HtmlElement('div');
		$this->dat->addAttribute('id', $id);
		$this->dat->addAttribute('class','editable_image_wrapper');
	}

	/**
	 *
	 */
	function __destruct() {

		//TODO - Insert your code here
	}
	
	public function finalize(){
		$this->addJSInit( '$(document).ready( function() {
		$(\'.preview_link\').lightBox();
		$(\'.imageTitle\').Truncate({length:12,spaceout:3});
		 });' );
		parent::finalize();
		$this->addControls();
		$this->output->imgs = (string)$this->dat->asXML();
	}
	/**
	 * We should only ever receive image objects
	 * (non-PHPdoc)
	 * @see Display::addChild()
	 */
	public function addChild($display,$token=null){
		if( !get_class($display)){
			throw new Exception("You can only supply Image objects to Editable Image Wrappers not ".get_class($display), 90);
		}
		$frame = $this->HtmlElement('div');
		$frame->addAttribute('class', 'framesection');
		$frame = $frame->addChild($display->output->imgs);
		$this->dat = $this->dat->addChild($frame);
	}
	/**
	 * last minute addition of controls
	 */
	protected function addControls( ){
		$controls = $this->HtmlElement('div');
		$controls->addAttribute('class', 'controls');
		$title = $this->HtmlElement('span',$this->title);
		$title->addAttribute('class', 'imageTitle');
		$control_section = $this->HtmlElement('span',null,array('class'=> 'control_panel'));
		$preview_link = $this->HtmlElement('a','',array('id'=>$this->id,'class'=> 'preview_link','href'=>$this->preview));
		$edit_link = $this->HtmlElement('a','',array('class'=> 'edit_link','href'=>$this->editpath));
		$img = $this->HtmlElement('img','',array('alt'=>'preview image','src'=>'images/icons/view.png'));
		$preview_link = $preview_link->addChild($img);
		$img2 = $this->HtmlElement('img','',array('alt'=>'edit this item','src'=>'images/icons/edit.png'));
		$edit_link = $edit_link->addChild($img2);
		$control_section = $control_section->addChild($preview_link);
		$control_section = $control_section->addChild($edit_link);
		$controls = $controls->addChild($title);
		$controls = $controls->addChild($control_section);
		$this->dat = $this->dat->addChild($controls);
	}
	
}


?>